#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>


//文件I/O
int main(int argc, char* argv[])
{
	int pf;
	int ret;
	char but1[32] = "xiao_yang nb\n";
	char but2[32] = {0};

	pf = open("1.txt", O_RDWR | O_CREAT | O_TRUNC, 0664);
	if(pf < 0)
	{
		perror("open");
		return -1;

	}

	//查看文件符
	printf("文件的描述符%d\n", pf);

	//写文件
	ret = write(pf, but1, strlen(but1));
	if(ret = EOF)
	{
		perror("writre");
		goto EDN;

	}else
	{
		printf("成功写入\n");
		printf("ret = %d",ret);
	}

	//查看文件指针偏移量
	ret = lseek(pf, 0, SEEK_SET);
	printf("文件指针偏移量%d",ret);


	//读文件
	ret = read(pf, but2, 32);
	if(ret < 0)
	{
		perror("read");
		goto EDN;

	}else
	{
		printf("读取完毕\n");
		printf("buf = %s", but2);
	}




//关闭文件
EDN:
	close(pf);
	return 0;
}


